#创建目录&权限
sudo mkdir -p /home/mysql/data  /home/mysql/conf.d
cd /home/mysql/
sudo chmod 770 -R ./*
sudo chown root:root -R ./*

#运行临时容器
docker run -d --rm --name tmp_mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql-server

#配置文件
sudo docker cp tmp_mysql:/etc/my.cnf /home/mysql/conf.d
docker kill tmp_mysql
echo 'lower_case_table_names=1' >> /home/mysql/conf.d/my.cnf
cat /home/mysql/conf.d/my.cnf
docker kill mysql
docker rm mysql

#运行正式容器
docker run -d --name  mysql --network=host \
--restart=always \
-v /home/mysql/conf.d/my.cnf:/etc/my.cnf \
-v /home/mysql/data:/var/lib/mysql \
-e TZ=Asia/Shanghai -e MYSQL_ROOT_PASSWORD=steden@123 mysql-server --lower_case_table_names=1
sleep 30s
docker logs mysql

#修改root密码、访问权限
docker exec -it mysql bash
mysql -uroot -psteden@123
set GLOBAL max_connections=10000;
use mysql
update user set Host='%' where User='root';
select User,Host FROM user;
flush privileges;
exit
exit